package com.lwp.spring.startup;

import com.lwp.spring.config.RootConfig;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

/**
 * AnnotationConfigDispatcherServletInitializer
 * 纯注解的方式增加springmvc配置
 *
 * @author lanwenping
 * @version 1.0
 * @date 2020/6/7 13:37
 */
public class AnnotationConfigDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
    /**
     * 独立的应用
     * createRootApplicationContext() root application context
     * @return
     */
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[]{RootConfig.class};
    }

    /**
     * web 应用填写这个配置就可以
     * createServletApplicationContext() Servlet application context
     * @return
     */
    @Override
    protected Class<?>[] getServletConfigClasses() {
//        return new Class[0];
        return new Class<?>[]{RootConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
//        return new String[0];
//        return new String[]{"/"};
        return new String[]{"*.do"};
    }


    /**
     * 注册 filter
     */
    @Override
    protected Filter[] getServletFilters() {

        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        characterEncodingFilter.setForceEncoding(true);

        return new Filter[]{characterEncodingFilter};
    }

}
